﻿#include "LoadingRing.h"
#include <QPainter>

LoadingRing::LoadingRing(QWidget* parent)
    : QWidget(parent)
{
    setFixedSize(64, 64);
    setAttribute(Qt::WA_TransparentForMouseEvents);

    connect(&m_timer, &QTimer::timeout, this, [=](){
        m_angle = (m_angle + 6) % 360;
        update();
    });

    m_timer.start(16);  // 60fps
}

void LoadingRing::paintEvent(QPaintEvent*)
{
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);

    // ---- 绘制旋转圆环 ----
    QRectF ringRect(
        3, 3,
        width() - 6,
        height() - 6
        );

    p.translate(ringRect.center());
    p.rotate(m_angle);
    p.translate(-ringRect.center());

    QPen pen(QColor("#E0900C"), 6);
    pen.setCapStyle(Qt::RoundCap);
    p.setPen(pen);
    p.drawArc(ringRect, 0, 120 * 16); // 120° 小圆弧
}
